package com.ruoyi.js.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.js.domain.JsMatchValue;
import com.ruoyi.js.service.IJsMatchValueService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 比赛分值Controller
 * 
 * @author greejoy
 * @date 2024-10-17
 */
@Controller
@RequestMapping("/js/matchValue")
public class JsMatchValueController extends BaseController
{
    private String prefix = "js/matchValue";

    @Autowired
    private IJsMatchValueService jsMatchValueService;

    @RequiresPermissions("js:matchValue:view")
    @GetMapping()
    public String matchValue(Long matchId, ModelMap mmap)
    {
        mmap.put("matchId", matchId);
        return prefix + "/matchValue";
    }

    /**
     * 查询比赛分值列表
     */
    @RequiresPermissions("js:matchValue:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JsMatchValue jsMatchValue)
    {
        startPage();
        List<JsMatchValue> list = jsMatchValueService.selectJsMatchValueList(jsMatchValue);
        return getDataTable(list);
    }

    /**
     * 导出比赛分值列表
     */
    @RequiresPermissions("js:matchValue:export")
    @Log(title = "比赛分值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JsMatchValue jsMatchValue)
    {
        List<JsMatchValue> list = jsMatchValueService.selectJsMatchValueList(jsMatchValue);
        ExcelUtil<JsMatchValue> util = new ExcelUtil<JsMatchValue>(JsMatchValue.class);
        return util.exportExcel(list, "matchValue");
    }

    /**
     * 新增比赛分值
     */
    @GetMapping("/add")
    public String add(Long matchId, ModelMap mmap)
    {
        mmap.put("matchId", matchId);
        return prefix + "/add";
    }

    /**
     * 新增保存比赛分值
     */
    @RequiresPermissions("js:matchValue:add")
    @Log(title = "比赛分值", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JsMatchValue jsMatchValue)
    {
        return toAjax(jsMatchValueService.insertJsMatchValue(jsMatchValue));
    }

    /**
     * 修改比赛分值
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JsMatchValue jsMatchValue = jsMatchValueService.selectJsMatchValueById(id);
        mmap.put("jsMatchValue", jsMatchValue);
        return prefix + "/edit";
    }

    /**
     * 修改保存比赛分值
     */
    @RequiresPermissions("js:matchValue:edit")
    @Log(title = "比赛分值", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JsMatchValue jsMatchValue)
    {
        return toAjax(jsMatchValueService.updateJsMatchValue(jsMatchValue));
    }

    /**
     * 删除比赛分值
     */
    @RequiresPermissions("js:matchValue:remove")
    @Log(title = "比赛分值", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jsMatchValueService.deleteJsMatchValueByIds(ids));
    }
}
